*Description: See README File

cd "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\ICPSR_02896" 

*1860 Census*
use "DS0009\02896-0009-Data.dta", clear
drop if county~=0
gen totpop_1860 = totpop
gen indpop_1860 = indtot
label var totpop_1860 "total population in 1860"
label var indpop_1860 "indian pop in 1860"
gen whtot_1860 = whtot 
label var whtot_1860 "white pop in 1860"
gen livstock_1860 = livstock
label var livstock_1860 "value of farm livestock in 1860"
keep state name totpop_1860 indpop_1860 whtot_1860 livstock_1860
replace name="DAKOTA" if name=="DAKOTA TERRITORY"
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1860_1" , replace

use "DS0010\02896-0010-Data.dta", clear
gen natpop_1860 = natpop
label var natpop_1860 "number of native born persons"
gen pbasia_1860 = pbasia
label var pbasia_1860 "total number of persons born in Asia, 1860"
gen pbneur_1860 = pbbelg + pbdenmar + pbenglan + pbfrance + pbaustri + pbgerman + pbirelan+ pbscot + pbsweden + pbswitz + pbhollan +pbnorway
label var pbneur_1860 "total number of persons born in north western europe, 1860"
gen pbseur_1860= pbitaly + pbspain + pbportug + pbpoland + pbrussia + pbgreece +pbturkey 
label var pbseur_1860 "persons born in sourthern or eastern europe, 1860"
gen pbmexico_1860 = pbmexico
label var pbmexico_1860 "persons born in mexico, 1860"
gen acres_1860 =acres
label var acres_1860 "total land area in acres, 1860"
gen area_1860 =area
label var area_1860 "total land area in SQ, 1860"
gen rrmi_1860 = rrmi60
label var rrmi_1860 "rr miles at end of 1859"
gen taxst_1860 = taxstate
label var taxst_1860 "amount of state taxes, 1860" 
keep state name natpop_1860 pbasia_1860 pbneur_1860 pbseur_1860 pbmexico_1860 acres_1860 area_1860 rrmi_1860 taxst_1860
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1860_2" , replace

joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1860_1.dta", unmatched(both)
drop _merge
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1860.dta", replace

*1870 Census*
use "DS0011\02896-0011-Data.dta", clear
drop if county~=0
gen totpop_1870 = totpop
gen indpop_1870 = indtot
label var totpop_1870 "total population in 1870"
label var indpop_1870 "indian pop in 1870"
gen whtot_1870 = whtot 
label var whtot_1870 "white pop in 1870"
gen livstock_1870 = livstock
label var livstock_1870 "value of farm livestock in 1870"
gen taxst_1870 = taxstate
label var taxst_1870 "amount of state taxes, 1870" 
keep state name totpop_1870 indpop_1870 whtot_1870 livstock_1870 taxst_1870
replace name="DAKOTA" if name=="DAKOTA TERRITORY"
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1870_1" , replace

use "DS0012\02896-0012-Data.dta", clear
gen natpop_1870 = natpop
label var natpop_1870 "number of native born persons"
gen pbasia_1870 = pbasia
label var pbasia_1870 "total number of persons born in Asia, 1870"
gen pbneur_1870 = pbbelg + pbdenmar + pbengl + pbfrance + pbaustri + pbgerm + pbirelan+ pbscot + pbsweden + pbswitz + pbhollan +pbnorway
label var pbneur_1870 "total number of persons born in north western europe, 1870"
gen pbseur_1870= pbitaly + pbspain + pbportug + pbpoland + pbrussia + pbgreece +pbturkey 
label var pbseur_1870 "persons born in sourthern or eastern europe, 1870"
gen pbmexico_1870 = pbmexico
label var pbmexico_1870 "persons born in mexico, 1870"
keep state name natpop_1870 pbasia_1870 pbneur_1870 pbseur_1870 pbmexico_1870
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1870_2" , replace

joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1870_1.dta", unmatched(both)
drop _merge
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1870.dta", replace

**Employment for 1870*
use "DS0013\02896-0013-Data.dta", clear
gen agemp_1870 = agemp
label var agemp_1870 "total engaged in ag labor in 1870"
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\Emp1870.dta", replace

*1880 Census*
use "DS0015\02896-0015-Data.dta", clear
drop if county~=0
gen totpop_1880 = totpop
gen indpop_1880 = indtot
gen natpop_1880 = nbtot
label var totpop_1880 "total population in 1880"
label var indpop_1880 "indian pop in 1880"
gen whtot_1880 = whtot 
label var whtot_1880 "white pop in 1880"
gen livstock_1880 = livstock
label var livstock_1880 "value of farm livestock in 1880"
keep state name totpop_1880 indpop_1880 whtot_1880 livstock_1880 natpop_1880
replace name="DAKOTA" if name=="DAKOTA TERRITORY"
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1880_1" , replace

use "DS0016\02896-0016-Data.dta", clear
gen pbasia_1880 = pbasia
label var pbasia_1880 "total number of persons born in Asia, 1880"
gen pbneur_1880 = pbbelg + pbdenmar + pbengl + pbfrance + pbaustri + pbgerm + pbirelan+ pbscot + pbsweden + pbswitz + pbhollan +pbnorway
label var pbneur_1880 "total number of persons born in north western europe, 1880"
gen pbseur_1880= pbitaly + pbspain + pbportug + pbpoland + pbrussia + pbgreece +pbturkey 
label var pbseur_1880 "persons born in sourthern or eastern europe, 1880"
gen pbmexico_1880 = pbmexico
label var pbmexico_1880 "persons born in mexico, 1880"
gen rrmi_1880 = rrmile80
label var rrmi_1880 "number of rr miles completed by 1880"
keep state name pbasia_1880 pbneur_1880 pbseur_1880 pbmexico_1880  rrmi_1880
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1880_2" , replace

joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1880_1.dta", unmatched(both)
drop _merge
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1880.dta", replace

use "DS0017\02896-0017-Data.dta", clear
gen agemp_1880 = aglatot
label var agemp_1880 "total engaged in ag labor in 1880"
gen mineemp_1880 = minetot
label var mineemp_1880 "total employed in mining in 1880"
gen rremp_1880 = rrtot
label var rremp_1880 "total employed in railroads in 1880"
gen stockemp_1880 = drovtot
label var stockemp_1880 "total number of stock-raisers herders in 1880"
gen lftot_1880 = lftot
label var lftot_1880 "total number of employed in 1880" 
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\Emp1880" , replace

*1890 Census*
use "DS0018\02896-0018-Data.dta", clear
drop if county~=0
gen totpop_1890 = totpop
gen indpop_1890 = indtot
gen natpop_1890 = nbmtot + nbftot
label var totpop_1890 "total population in 1890"
label var indpop_1890 "indian pop in 1890"
gen whtot_1890 = whtot 
label var whtot_1890 "white pop in 1890"
gen livstock_1890 = livstock
label var livstock_1890 "value of farm livestock in 1890"
keep state name totpop_1890 indpop_1890 whtot_1890 livstock_1890 natpop_1890
replace name="DAKOTA" if name=="DAKOTA TERRITORY"
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1890_1" , replace

use "DS0019\02896-0019-Data.dta", clear
gen pbasia_1890 = pbasia
label var pbasia_1890 "total number of persons born in Asia, 1890"
gen pbneur_1890 = pbbelg + pbdenmar + pbengl + pbfrance + pbaustri + pbgerm + pbirelan+ pbscot + pbsweden + pbswitz + pbhollan +pbnorway
label var pbneur_1890 "total number of persons born in north western europe, 1890"
gen pbseur_1890= pbitaly + pbspain + pbportug + pbpoland + pbrussia + pbgreece +pbturkey + pbbohem + pbhungar 
label var pbseur_1890 "persons born in sourthern or eastern europe, 1890"
gen pbmexico_1890 = pbmexico
label var pbmexico_1890 "persons born in mexico, 1890"
keep state name pbasia_1890 pbneur_1890 pbseur_1890 pbmexico_1890
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1890_2" , replace

joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1890_1.dta", unmatched(both)
drop _merge
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1890.dta", replace

*1900 Census*
use "DS0020\02896-0020-Data.dta", clear
drop if county~=0
gen totpop_1900 = totpop
gen natpop_1900 = nbmtot + nbftot
label var totpop_1900 "total population in 1900"
gen whtot_1900 = whtot 
label var whtot_1900 "white pop in 1900"
gen livstock_1900 = livstock
label var livstock_1900 "value of farm livestock in 1900"
keep state name totpop_1900  whtot_1900 livstock_1900 natpop_1900
replace name="DAKOTA" if name=="DAKOTA TERRITORY"
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1900_1" , replace

use "DS0020\02896-0020-Data.dta", clear
drop if county~=0
gen pbasia_1900 = pbasia
label var pbasia_1900 "total number of persons born in Asia, 1900"
gen pbneur_1900 = pbbelg + pbdenmar + pbengl + pbfrance + pbaustri + pbgerman + pbirelan+ pbscot + pbsweden + pbswitz + pbhollan +pbnorway
label var pbneur_1900 "total number of persons born in north western europe, 1900"
replace pbitaly=0 if pbitaly==.
replace pbspain=0 if pbspain==.
replace pbportug =0 if pbportug ==.
replace pbpoland=0 if pbpoland ==.
replace pbrussia=0 if pbrussia ==.
replace pbgreece=0 if pbgreece ==.
replace pbturkey=0 if pbturkey ==.
replace pbbohem=0 if pbbohem ==.
replace pbhungar=0 if pbhungar ==.
replace pbrumani=0 if pbrumani ==.
gen pbseur_1900= pbitaly + pbspain + pbportug + pbpoland + pbrussia + pbgreece +pbturkey + pbbohem + pbhungar + pbrumani
label var pbseur_1900 "persons born in sourthern or eastern europe, 1900"
gen pbmexico_1900 = pbmexico
label var pbmexico_1900 "persons born in mexico, 1900"
gen area_1900 = area
label var area_1900 "sq miles in 1900"
keep state name pbasia_1900 pbneur_1900 pbseur_1900 pbmexico_1900 area_1900
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1900_2" , replace

joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1900_1.dta", unmatched(both)
drop _merge
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1900.dta", replace

*1910 Census*
use "DS0022\02896-0022-Data.dta", clear
drop if county~=0
gen totpop_1910 = totpop
gen natpop_1910 = totpop-fbwtot
*note: this is the total population minus the foreign born white population*
label var totpop_1910 "total population in 1910"
gen whtot_1910 = whtot 
label var whtot_1910 "white pop in 1910"
keep state name totpop_1910  whtot_1910 natpop_1910
replace name="DAKOTA" if name=="DAKOTA TERRITORY"
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1910_1" , replace

use "DS0022\02896-0022-Data.dta", clear
drop if county~=0
gen pbneur_1910 = pbwbelg + pbwdenmk + pbwengla + pbwfran + pbwaustr + pbwgerm + pbwirel+ pbwscot + pbwswed + pbwswitz + pbwholl +pbwnorw
label var pbneur_1910 "total number of white persons born in north western europe, 1910"
replace pbwitaly=0 if pbwitaly==.
replace pbwspain=0 if pbwspain==.
replace pbwportu =0 if pbwportu ==.
replace pbwruss=0 if pbwruss ==.
replace pbwgreec=0 if pbwgreec ==.
replace pbwturk=0 if pbwturk ==.
replace pbwhung=0 if pbwhung ==.
replace pbwruman=0 if pbwruman ==.
replace pbwserb=0 if pbwserb==.
replace pbwbulg=0 if pbwbulg==.
gen pbseur_1910= pbwitaly + pbwspain + pbwportu + pbwserb +  pbwruss + pbwgreec +pbwturk + pbwhung + pbwruman + pbwbulg
label var pbseur_1910 "white persons born in sourthern or eastern europe, 1910"
gen pbmexico_1910 = pbwmexi
label var pbmexico_1910 "white persons born in mexico, 1910"
gen area_1910 = area
label var area_1910 "sq miles in 1910"
keep state name  pbneur_1910 pbseur_1910 pbmexico_1910 area_1910
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1910_2" , replace

joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1910_1.dta", unmatched(both)
drop _merge
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1910.dta", replace

*1920 Census*
use "DS0024\02896-0024-Data.dta", clear
drop if county~=0
gen totpop_1920 = totpop
gen natpop_1920 = totpop-fbwmtot- fbwftot
*note: this is the total population minus the foreign born white population*
label var totpop_1920 "total population in 1920"
gen whtot_1920 = whtot 
label var whtot_1920 "white pop in 1920"
keep state name totpop_1920  whtot_1920 natpop_1920
replace name="DAKOTA" if name=="DAKOTA TERRITORY"
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1920_1" , replace

use "DS0024\02896-0024-Data.dta", clear
drop if county~=0
gen pbneur_1920 = pbwbelg + pbwdenmk + pbwengla + pbwfran + pbwaustr + pbwgerm + pbwirel+ pbwscot + pbwswed + pbwswitz + pbwholl +pbwnorw
label var pbneur_1920 "total number of white persons born in north western europe, 1920"
replace pbwitaly=0 if pbwitaly==.
replace pbwspain=0 if pbwspain==.
replace pbwportu =0 if pbwportu ==.
replace pbwruss=0 if pbwruss ==.
replace pbwgreec=0 if pbwgreec ==.
replace pbwhung=0 if pbwhung ==.
replace pbwruman=0 if pbwruman ==.
replace pbwbulg=0 if pbwbulg==.
gen pbseur_1920= pbwitaly + pbwspain + pbwportu + pbwruss + pbwgreec + pbwhung + pbwruman + pbwbulg
label var pbseur_1920 "white persons born in sourthern or eastern europe, 1920"
gen pbmexico_1920 = pbwmexi
label var pbmexico_1920 "white persons born in mexico, 1920"
gen area_1920 = area
label var area_1920 "sq miles in 1920"
keep state name  pbneur_1920 pbseur_1920 pbmexico_1920 area_1920
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1920_2" , replace

joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1920_1.dta", unmatched(both)
drop _merge
save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1920.dta", replace


**CREATING 1860 to 1920 PANEL*

use "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1880.dta", clear

joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1860.dta", unmatched(both) 
drop _merge
joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1870.dta", unmatched(both) 
drop _merge
joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1890.dta", unmatched(both) 
drop _merge
joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1900.dta", unmatched(both) 
drop _merge
joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1910.dta", unmatched(both) 
drop _merge
joinby name using "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\Haines Census Data\PopData1920.dta", unmatched(both) 
drop _merge

drop if state==100
sort name
quietly reshape long totpop_ natpop_ acres_ area_ , i(name) j(year)
keep natpop_ acres_ area_ name year state

save "D:\Dropbox\Dropbox\Lueck and Parker\JAERE submission\Final Version 2024\Data and Code for Replication\PopData1860_1920.dta", replace



